package com.example.room

import android.content.Context
import androidx.room.Room
import com.example.room.db.AppDatabase

object DBUtil {

    private lateinit var dataBase:AppDatabase


    /**
     * 初始化数据库
     */

    fun initDB(context: Context){
        dataBase = Room.databaseBuilder(context,AppDatabase::class.java,"i_db").build()
    }

    /**
     * 获取数据库实例
     */
    fun getDataBase():AppDatabase{
        if(dataBase == null){
            throw RuntimeException("DataBase not initialized")
        }
        return dataBase
    }
}